﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using TlToolCordCreate.ViewMode;

namespace TlToolCordCreate
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class ucDatabase2 : UserControl
    {
        UiData1 uiData1;
        public ucDatabase2()
        {
            InitializeComponent();
            this.DataContext = uiData1 = new UiData1() ;
            this.Loaded += UcDatabase2_Loaded;
        }

        private void UcDatabase2_Loaded(object sender, RoutedEventArgs e)
        {
            if (uiData1.config.type == SqlSugar.DbType.MySql)
            {
                rbmysql.IsChecked = true;
            }

            if (uiData1.config.type == SqlSugar.DbType.SqlServer)
            {
                rbsql.IsChecked = true;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFolder(".");
        }
        /// <summary>
        /// 打开目录
        /// </summary>
        /// <param name="folderPath">目录路径（比如：C:\Users\Administrator\）</param>
        private static void OpenFolder(string folderPath)
        {
            if (string.IsNullOrEmpty(folderPath)) return;

            Process process = new Process();
            ProcessStartInfo psi = new ProcessStartInfo("Explorer.exe");
            psi.Arguments = folderPath;
            process.StartInfo = psi;

            try
            {
                process.Start();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                process?.Close();

            }

        }

        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            if (rbmysql.IsChecked==true) {
                uiData1.config.type = SqlSugar.DbType.MySql;
            }
            if (rbsql.IsChecked == true)
            {
                uiData1.config.type = SqlSugar.DbType.SqlServer;
            }
        }
    }
}
